#ifndef CLIENT_H
#define CLIENT_H

#include <QTcpSocket>

#include <QGraphicsView>
#include <QTimer>
#include <QMutex>

#include "sensor/Laser.h"
#include "sensor/Camera.h"
#include "sensor/MJPEGClient.h"
#include "sensor/RS232Motor.h"

#include "qdisplay/QwImageViewer.h"
#include "qdisplay/QiLaserScan.h"
#include "qdisplay/QwController.h"


class Client : public QObject
{
    Q_OBJECT

public:    
    Client();
    ~Client();

    void run();
    void display();

    int	m_cmd_left;
    int m_cmd_right;

    CameraData m_camera;
    LaserData m_laser;

public slots:
    void gotNewSensorData( const QImage* pic );
    void gotNewSensorData( const RS232Data* sensorL, const RS232Data* sensorR );
    void gotNewSensorData( LaserData* laserdata );

    void tcpDataToRead();
    void tcpDataToSend( int cmd_left, int cmd_right );
    void tcpError( QAbstractSocket::SocketError error );
    void tcpServerConnected();
    void tcpServerDisconnected();

private:      
    void runThreadCamera();
    void runThreadTCPData();

    void displayLaser();
    void displayCamera();
    void displayController();

    MJPEGClient* m_mjpegClient;
    QwImageViewer* m_cameraViewer;
    QiLaserScan* m_laserViewer;
    QwController* m_controllerViewer;

    QGraphicsScene* m_scene;
    QGraphicsView* m_view;

    QTcpSocket m_socket;
    QString m_server_name;

    QMutex m_mutex;

};

unsigned long int getCurrentTime();


#endif // CLIENT_H
